package com.linkwechat.fileservice.service.impl;

import com.linkwechat.common.config.LinkWeChatConfig;
import com.linkwechat.fileservice.config.MinioConfig;
import com.linkwechat.fileservice.service.IFileService;
import com.linkwechat.fileservice.utils.FileUploadUtils;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author: houyong
 * @date: 2024年12月05日 9:27
 */
@Service
@ConditionalOnProperty(prefix = "linkwechat.file", value = "object", havingValue = "minio")
public class MinioFileServiceImpl implements IFileService {

    @Autowired
    private LinkWeChatConfig linkWeChatConfig;


    @Autowired
    private MinioClient minioClient;


    @Override
    public String uploadFile(MultipartFile file) throws Exception {
        String resourceId = FileUploadUtils.uploadMinioFile(linkWeChatConfig.getFile().getCos().getBucketName(), file,minioClient);
        return linkWeChatConfig.getFile().getCos().getCosImgUrlPrefix()
                + resourceId;
    }
}
